package com.dm.hdfxxt.productmanage.service.impl;

import com.dm.hdfxxt.productmanage.mapper.ProductMapper;
import com.dm.hdfxxt.productmanage.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    /**
         * @Description 保存产品信息
         * @Author zhangxue
         * @Date 11:19 2018/10/30
         * @Param
         * @retrun
         **/
    @Override
    public Map<String, Object> saveProduct(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        int i = productMapper.saveProduct(param);
        if(i==1){
            StatusMap.put("Status",1);//保存成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }

    /**
     * @Description 编辑产品信息
     * @Author zhangxue
     * @Date 11:19 2018/10/30
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> editProduct(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        int i = productMapper.editProduct(param);
        if(i==1){
            StatusMap.put("Status",1);//编辑成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//保存失败
        }
        return StatusMap;
    }

    /**
     * @Description 删除产品信息
     * @Author zhangxue
     * @Date 11:19 2018/10/30
     * @Param
     * @retrun
     **/
    @Override
    public Map<String, Object> delProduct(Map<String, Object> param) {
        Map<String,Object> StatusMap = new HashMap<String, Object>();
        int i = productMapper.delProduct(param);
        if(i==1){
            StatusMap.put("Status",1);//删除成功
        }else{
            //如果不是影响一条，直接回滚
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            StatusMap.put("Status",0);//删除失败
        }
        return StatusMap;
    }

    /**
         * @Description 查询所有产品
         * @Author zhangxue
         * @Date 11:36 2018/10/30
         * @Param
         * @retrun
         **/
    @Override
    public List<Map<String, Object>> queryAllProduct(Map<String, Object> param) {
        List<Map<String,Object>> ResultList = productMapper.queryAllProduct(param);
        return ResultList;
    }
}
